package com.opencloud.ywt.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.opencloud.common.model.PageParams;
import com.opencloud.ywt.client.model.entity.*;
import com.opencloud.ywt.provider.mapper.*;
import com.opencloud.ywt.provider.service.BhyfCityService;
import com.opencloud.ywt.provider.service.BhyfSportService;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 动量服务
 * @author yeyong
 */

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class BhyfSportServiceImpl implements BhyfSportService {
    @Autowired
    private BhyfXhbSportClassMapper bhyfXhbSportClassMapper;

    @Autowired
    private BhyfXhbSportPersonCommentMapper bhyfXhbSportPersonCommentMapper;

    @Autowired
    private BhyfXhbAllSportMapper bhyfXhbAllSportMapper;

    @Autowired
    private BhyfXhbGardensportMapper bhyfXhbGardensportMapper;

    @Autowired
    private BhyfXhbSkipPersonMapper bhyfXhbSkipPersonMapper;

    @Override
    public List<BhyfXhbSportClass> findClassSportList(Integer gid,Integer classid, String startTime, String endTime) {
        QueryWrapper<BhyfXhbSportClass> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(ObjectUtils.isNotEmpty(gid),BhyfXhbSportClass::getGardenId,gid);
        queryWrapper.lambda().eq(ObjectUtils.isNotEmpty(classid) && classid>0,BhyfXhbSportClass::getClassId,classid);
        queryWrapper.lambda().between(ObjectUtils.isNotEmpty(startTime) && ObjectUtils.isNotEmpty(endTime), BhyfXhbSportClass::getSportDate, startTime, endTime);
        queryWrapper.lambda().orderByDesc(BhyfXhbSportClass::getSportDate);
        return bhyfXhbSportClassMapper.selectList(queryWrapper);
    }

    @Override
    public List<BhyfXhbSportPersonComment> findPersonSportList(Integer personid,String startTime, String endTime){
        List<BhyfXhbSportPersonComment> returnList = new ArrayList<>();
        QueryWrapper<BhyfXhbSportPersonComment> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(ObjectUtils.isNotEmpty(personid),BhyfXhbSportPersonComment::getPersonid,personid);
        queryWrapper.lambda().between(ObjectUtils.isNotEmpty(startTime) && ObjectUtils.isNotEmpty(endTime), BhyfXhbSportPersonComment::getSportdate, startTime, endTime);
        queryWrapper.lambda().orderByDesc(BhyfXhbSportPersonComment::getSportdate);
        returnList= bhyfXhbSportPersonCommentMapper.selectList(queryWrapper);
        return returnList;
    }

    @Override
    public List<BhyfXhbAllSport> findAllSportList() {
        QueryWrapper<BhyfXhbAllSport> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().orderByDesc(BhyfXhbAllSport::getCreatetime);
        return bhyfXhbAllSportMapper.selectList(queryWrapper);
    }

    @Override
    public List<BhyfXhbGardensport> findGardenSportList(Integer gid) {
        QueryWrapper<BhyfXhbGardensport> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(ObjectUtils.isNotEmpty(gid),BhyfXhbGardensport::getGid,gid);
        queryWrapper.lambda().orderByDesc(BhyfXhbGardensport::getCreatetime);
        return bhyfXhbGardensportMapper.selectList(queryWrapper);
    }

    @Override
    public List<BhyfXhbSkipPerson> findSkipPersonList(String startTime, String endTime) {
        QueryWrapper<BhyfXhbSkipPerson> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().between(ObjectUtils.isNotEmpty(startTime) && ObjectUtils.isNotEmpty(endTime), BhyfXhbSkipPerson::getSkipdate, startTime, endTime);
        queryWrapper.lambda().orderByDesc(BhyfXhbSkipPerson::getCreatetime);
        return bhyfXhbSkipPersonMapper.selectList(queryWrapper);
    }

    @Override
    public BhyfXhbAllSport findBhyfXhbAllSportById(Integer id){
        return bhyfXhbAllSportMapper.selectById(id);
    }

    @Override
    public BhyfXhbAllSport addBhyfXhbAllSport(BhyfXhbAllSport entiy)
    {
        bhyfXhbAllSportMapper.insert(entiy);
        return entiy;
    }

    @Override
    public void updateBhyfXhbAllSport(BhyfXhbAllSport entiy)
    {
        bhyfXhbAllSportMapper.updateById(entiy);
    }


    @Override
    public BhyfXhbGardensport findBhyfXhbGardenSportById(Integer id){
        return bhyfXhbGardensportMapper.selectById(id);
    }

    @Override
    public BhyfXhbGardensport addBhyfXhbGardenSport(BhyfXhbGardensport entiy)
    {
        bhyfXhbGardensportMapper.insert(entiy);
        return entiy;
    }

    @Override
    public void updateBhyfXhbGardenSport(BhyfXhbGardensport entiy)
    {
        bhyfXhbGardensportMapper.updateById(entiy);
    }


    @Override
    public void deleteBhyfXhbGardenSport(Integer id)
    {
        bhyfXhbGardensportMapper.deleteById(id);
    }

    @Override
    public List<BhyfXhbSportPersonCommentResult> getPersonSportCommentResult(Integer gid, Integer gradenum,String startdate,String enddate){
        return bhyfXhbSportPersonCommentMapper.getPersonSportCommentResult(gid,gradenum,startdate,enddate);
    }
}